<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>

	<input type="text" id="input">
	<button id="send" type="button">发送</button>

	<script>
		const ws = new WebSocket('ws://localhost:5050');

		ws.onopen = function () {
			ws.send('来自客户端的message');
			document.getElementById('send').onclick = function () {
				ws.send(document.getElementById('input').value);
			}
		}

		ws.onmessage = function (e) {
			let p = document.createElement('p');
			p.innerHTML = e.data;
			document.body.appendChild(p);
			console.log(e, e.data);
		}
	</script>
</body>

</html>